<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>旅游管理系统 - 登录</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body { background: #f0f2f5; font-family: 'Microsoft YaHei', Arial, sans-serif; }
        .login-container {
            width: 350px; margin: 100px auto; background: #fff; border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1); padding: 40px 30px 30px 30px;
        }
        .login-title { text-align: center; font-size: 24px; margin-bottom: 30px; color: #1890ff; }
        .form-group { margin-bottom: 20px; }
        .form-group label { display: block; margin-bottom: 8px; color: #333; }
        .form-group input {
            width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 4px;
            font-size: 16px; box-sizing: border-box;
        }
        .login-btn {
            width: 100%; padding: 10px; background: #1890ff; color: #fff; border: none;
            border-radius: 4px; font-size: 18px; cursor: pointer; transition: background 0.2s;
        }
        .login-btn:hover { background: #40a9ff; }
        .error-msg { color: #f5222d; text-align: center; margin-bottom: 10px; }
    </style>
</head>
<body>
<div class="login-container">
    <div class="login-title">旅游管理系统登录</div>
    <div class="error-msg" id="errorMsg"></div>
    <div class="form-group">
        <label for="username">账号</label>
        <input type="text" id="username" placeholder="请输入账号">
    </div>
    <div class="form-group">
        <label for="password">密码</label>
        <input type="password" id="password" placeholder="请输入密码">
    </div>
    <button class="login-btn" onclick="login()">登录</button>
    <div style="text-align:center; margin-top:15px;">
        没有账号？<a href="register.html" style="color:#1890ff;text-decoration:none;">去注册</a>
    </div>
</div>
<script>
function login() {
    var username = document.getElementById('username').value.trim();
    var password = document.getElementById('password').value.trim();
    var errorMsg = document.getElementById('errorMsg');
    errorMsg.textContent = '';
    if (!username || !password) {
        errorMsg.textContent = '账号和密码不能为空！';
        return;
    }
    fetch('/api/user/login', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ username: username, password: password })
    })
    .then(response => response.json())
    .then(data => {
        if (data.success) {
            localStorage.setItem('currentUser', username); // 保存当前用户名
            window.location.href = '/manage.html'; // 登录成功跳转管理页面
        } else {
            errorMsg.textContent = data.message || '账号或密码错误！';
        }
    })
    .catch(() => {
        errorMsg.textContent = '登录请求失败，请稍后重试！';
    });
}
</script>
</body>
</html> 